#include <sstream>

#include "role_data.hpp"

RoleData::RoleData()
	: _id(0),
	  _name(""),
	  _passwd(""),
	  _pic_id(0),
	  _sex(0),
	  _age(0),
	  _province(""),
	  _city(""),
	  _level(0),
	  _title(0),
	  _silver(0),
	  _lost_num(0),
	  _win_num(0)
{
}

void RoleData::serialize(Streamer & streamer)
{
	streamer & _id
		     & _name
			 & _passwd
			 & _pic_id
			 & _sex
			 & _age
			 & _province
			 & _city
			 & _level
			 & _title
			 & _silver
			 & _lost_num
			 & _win_num;
}

const std::string RoleData::to_string() const
{
	std::ostringstream oss;
	oss << "{id: " << _id
		<< ", name: " << _name
		<< ", passwd: " << _passwd
		<< ", pic_id: " << (int)_pic_id
		<< ", sex: " << (int)_sex
		<< ", age: " << (int)_age
		<< ", province: " << _province
		<< ", city: " << _city
		<< ", level: " << (int)_level
		<< ", title: " << (int)_title
		<< ", silver: " << _silver
		<< ", lost num: " << _lost_num
		<< ", win num: " << _win_num;

	return oss.str();
}

uint32_t RoleData::size() const
{
	return (sizeof(_id) + sizeof(uint32_t) + _name.size() +
			sizeof(uint32_t) + _passwd.size() + sizeof(_pic_id) +
			sizeof(_sex) + sizeof(_age) +
			sizeof(uint32_t) + _province.size() +
			sizeof(uint32_t) + _city.size() +
			sizeof(_level) + sizeof(_title) + 
			sizeof(_silver) + sizeof(_lost_num) +
			sizeof(_win_num));
}

